-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Add psycopg3 as a new backend #586
base: master
Are you sure you want to change the base?
Conversation
It's mostly ready, but I will double-check if I have missed anything, if there is any code that should have been updated. |
Never mind, this is not ready, there is a lot of work to do. |
@ansipunk psycopg3 is called simply psycopg. https://pypi.org/project/psycopg/ This version is already being supported. |
@tarsil Read |
@ansipunk got it. We are talking 2 completely different things. You meant the scheme support. Why is that needed? Normally postgres or asyncpg would suffice as internally is converted. What is the use case? |
@tarsil What? No. I mean conneciton management and connection pools. If you read the source code, you can see that it exclusively uses |
The use case is to use |
@ansipunk ok, let's start over. Apologies if I'm lost here. Internally uses asyncpg and aiopg yes for async driver but here https://github.com/encode/databases/blob/master/databases/backends/postgres.py it uses the SQL alchemy 2 dialect for it and internally the psycopg being used is the one shared before here. Now, based on your example we indeed do not support like that but it can be analysed and see what we could do to make it happen and if it's worth it. I hope I'm explaining properly? Also SQLAlchemy utils until recently, if I'm not mistaken, was incompatible with SQLA 2. I think that was addressed recently but I'm not 100% sure, I need to investigate |
Let me do some investigation here and come back to you soon? I read about the async support with psycopg (now 3) as well but I'm not 100% yet familiar with what we can actually do. |
5dcf235
to
ddd8aaa
Compare
As for the commit history, this is fucked up, hopefully we will just squash commits. |
bdb6dbe
to
ca7186a
Compare
ca7186a
to
cdbf97f
Compare
6824692
to
e7358af
Compare
f39f5eb
to
e7358af
Compare
Resolves #535.
I generally don't have time for this during weekdays, so if anyone wants to help out - feel free to fork my fork, we will merge it and make this thing work. Maybe @tomchristie still remembers how did he make it work for other drivers.
https://www.psycopg.org/psycopg3/docs/basic/adapt.html
TODO:
There are no timeouts specified for the driver, which in some cases might hang the process. Adding timeouts is fairly easy.
Currently there is a hacky solution to properly serialize and deserialize JSONs. While this works, this is far from perfect and we should figure out a better way to do it. Moreover, this hack will break compatibility with PostgreSQL's native Array type.
Possibly we can add
orjson
to optional dependencies to make serialization/deserialization faster.And maybe remove
aiopg
entirely?Not working:
cursor.execute()
- while it's possible, it might throw an error sometimes due to empty results list. Might add a simple try/catch there laterDone:
Asynchronous connection and connection pool using
psycopg3
.Renamed
postgres
backend toasyncpg
backend. Updateddatabases/core.py
to use new backends and support new DSN schemas.Mentioned that
psycopg3
may be used in README and docs. Added the new driver as an optional dependency tosetup.py
.Also updated tests that involve Starlette to work with their new API, otherwise the thing was throwing bunch of warnings.
Edited pipeline to use modern MariaDB instead of old MySQL - for some reason old MySQL image would kill performance on my machine and replacing it did the trick. I imagine this might be good for the pipelines, too, but needs some testing if necessary. Updated contributing page in the same fashion.
Test case status: